package com.aios.dao;

import com.aios.entity.Controller;
import com.aios.entity.Switch;
import com.aios.entity.Timer;
import com.aios.entity.TimerExample;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import com.aios.entity.mapper.TimerSetting;
import com.aios.entity.mapper.TimerSwitch;

import java.util.List;

public interface TimerMapper {
    int countByExample(TimerExample example);

    int deleteByExample(TimerExample example);

    int deleteByPrimaryKey(String id);

    int insert(Timer record);

   
    int insertSelective(Timer record);

  
    List<Timer> selectByExample(TimerExample example);

  
    Timer selectByPrimaryKey(String id);

    
    int updateByExampleSelective(@Param("record") Timer record, @Param("example") TimerExample example);

 
    int updateByExample(@Param("record") Timer record, @Param("example") TimerExample example);

   
    int updateByPrimaryKeySelective(Timer record);

    
    int updateByPrimaryKey(Timer record);
   
   @Select("SELECT COUNT(*) FROM timer WHERE STATUS = #{status}")
  	Integer countAllByStatus(@Param("status") Integer status);
   	
   	@Select("SELECT * FROM timer WHERE STATUS = #{status} ORDER BY SORT_ORDER LIMIT #{start}, #{size}")
    @ResultMap(value="MiniResultMap")
    List<Timer> findListPaginated(@Param("status") Integer status, 
			@Param("start") Integer start, @Param("size") Integer size);

   	@Select("SELECT * FROM timer WHERE ID=#{id}")
   	@ResultMap(value="TimerSettingResultMap")
	TimerSetting findByIdWithSchedule(@Param("id") String id);
   	
   	@Select("SELECT t.ID,t.NAME,s.NAME AS SNAME,t.TRIGER_TIME DIV 60 AS TIMER_HOUR,MOD(t.TRIGER_TIME,60) AS TIMER_MIN,t.SWITCH_SETTING FROM timer AS t, switch AS s,system_user_has_switch_panel AS suhsp WHERE t.SWITCH_ID = s.ID AND s.SWITCH_PANEL_ID= suhsp.SWITCH_PANEL_ID AND  suhsp.SYSTEM_USER_ID=#{id}")
	@ResultMap(value="TimerSwitchResultMap")
   	List<TimerSwitch> findTimerByUserId(@Param("id") String id);

  
   	
   	
   	
  
}